/*
 * Created on Aug 24, 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package schoolsource.model;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.logging.Level;

import schoolsource.sql.SchoolDBSQL;
import schoolsource.util.SchoolLogger;

/**
 *
 * @author Steven Steele
 * Copyright 2003
 *
 * Contains information for a school. This class is not used at the current time.
 */
public class SchoolContainer extends Container {

	// The map of timer buckets for all databases
	protected static Hashtable dbStores = new Hashtable(); 
	private IntegerItem schoolID =
		new IntegerItem(SchoolDBSQL.SCHOOLID, "1", true);
	private StringItem schoolName =
		new StringItem(SchoolDBSQL.SCHOOLNAME, "", false);
	private StringItem schoolAddress1 =
		new StringItem(SchoolDBSQL.SCHOOLADDR1, "", false);
	private StringItem schoolAddress2 =
		new StringItem(SchoolDBSQL.SCHOOLADDR2, "", false);
	private StringItem schoolCity =
		new StringItem(SchoolDBSQL.SCHOOLCITY, "", false);
	private StringItem schoolState =
		new StringItem(SchoolDBSQL.SCHOOLSTATE, "", false);
	private StringItem schoolZip =
		new StringItem(SchoolDBSQL.SCHOOLZIP, "", false);
	private StringItem schoolLogo =
		new StringItem(SchoolDBSQL.SCHOOLLOGO, "", false);
	private StringItem schoolLogoWidth =
		new StringItem(SchoolDBSQL.SCHOOLLOGOWIDTH, "", false);
	private StringItem schoolActiveMenuBarColor =
		new StringItem(SchoolDBSQL.SCHOOLACTIVEMENUBARCOLOR, "", false);
	private StringItem schoolInactiveMenuBarColor =
		new StringItem(SchoolDBSQL.SCHOOLINACTIVEMENUBARCOLOR, "", false);
	private StringItem schoolActiveLinkColor =
		new StringItem(SchoolDBSQL.SCHOOLACTIVELINKCOLOR, "", false);
	private StringItem schoolInactiveLinkColor =
		new StringItem(SchoolDBSQL.SCHOOLINACTIVELINKCOLOR, "", false);
	private StringItem schoolMenuHeadingColor =
		new StringItem(SchoolDBSQL.SCHOOLMENUHEADINGCOLOR, "", false);
	private StringItem schoolMenuBackgroundColor =
		new StringItem(SchoolDBSQL.SCHOOLMENUBACKGROUNDCOLOR, "", false);
	private StringItem schoolHeadingFont =
		new StringItem(SchoolDBSQL.SCHOOLHEADINGFONT, "", false);


	private SchoolContainer() {

	}

	private SchoolContainer(String dbName) {
		getSchoolID().setValue("1");

		SchoolDBSQL.getSchoolDBSQL(dbName).loadSchool(
			getValidationItems(),
			schoolID);
	}

	public static SchoolContainer getSchoolContainer(String dbName) {
		SchoolContainer returnVal = null;
		DBStore dbs = null;
		
		if ((dbs = (DBStore) dbStores.get(dbName)) == null) {
			dbs = new DBStore();
			dbStores.put(dbName, dbs);
			dbs.start();
		}
		if ((returnVal = (SchoolContainer) dbs.getContainer("1")) == null) {
			returnVal = new SchoolContainer();
			returnVal.getSchoolID().setValue("1");
			SchoolDBSQL.getSchoolDBSQL(dbName).loadSchool(returnVal.getValidationItems(), returnVal.getSchoolID());
			dbs.addContainer(returnVal, "1");
		}

		return returnVal;
	}

	/* (non-Javadoc)
	 * @see schoolsource.model.Container#getValidationItems()
	 */
	public Item[] getValidationItems() {
		ArrayList al = new ArrayList();
		al.add(schoolID);
		al.add(schoolName);
		al.add(schoolAddress1);
		al.add(schoolAddress2);
		al.add(schoolCity);
		al.add(schoolState);
		al.add(schoolZip);
		al.add(schoolLogo);
		al.add(schoolLogoWidth);
		al.add(schoolActiveMenuBarColor);
		al.add(schoolInactiveMenuBarColor);
		al.add(schoolActiveLinkColor);
		al.add(schoolInactiveLinkColor);
		al.add(schoolMenuHeadingColor);
		al.add(schoolMenuBackgroundColor);
		al.add(schoolHeadingFont);

		return (Item[]) al.toArray(new Item[al.size()]);
	}

	/**
	 * @return
	 */
	public IntegerItem getSchoolID() {
		return schoolID;
	}

	/**
	 * @return
	 */
	public StringItem getSchoolName() {
		return schoolName;
	}

	/**
	 * @return
	 */
	public StringItem getSchoolAddress1() {
		return schoolAddress1;
	}

	/**
	 * @return
	 */
	public StringItem getSchoolAddress2() {
		return schoolAddress2;
	}

	/**
	 * @return
	 */
	public StringItem getSchoolCity() {
		return schoolCity;
	}

	/**
	 * @return
	 */
	public StringItem getSchoolState() {
		return schoolState;
	}

	/**
	 * @return
	 */
	public StringItem getSchoolZip() {
		return schoolZip;
	}

	/**
	 * @return
	 */
	 public StringItem getSchoolLogo() {
		 return schoolLogo;
	 }

	/**
	 * @return
	 */
	 public StringItem getSchoolLogoWidth() {
		 return schoolLogoWidth;
	 }

	 /**
	  *
	  */
	 public StringItem getSchoolActiveMenuBarColor() {
		 return schoolActiveMenuBarColor;
	 }

	 /**
	  *
	  */
	 public StringItem getSchoolInactiveMenuBarColor() {
		 return schoolInactiveMenuBarColor;
	 }

	 /**
	  *
	  */
	 public StringItem getSchoolActiveLinkColor() {
		 return schoolActiveLinkColor;
	 }

	 /**
	  *
	  */
	 public StringItem getSchoolInactiveLinkColor() {
		 return schoolInactiveLinkColor;
	 }

	 /**
	  *
	  */
	 public StringItem getSchoolMenuHeadingColor() {
		 return schoolMenuHeadingColor;
	 }

	 /**
	  *
	  */
	 public StringItem getSchoolMenuBackgroundColor() {
		 return schoolMenuBackgroundColor;
	 }

	 /**
	  *
	  */
	 public StringItem getSchoolHeadingFont() {
		 return schoolHeadingFont;
	 }

	/**
	 * Prints the values of the container.
	 */
	public void printItems() {
		SchoolLogger.logger.log(
			Level.INFO,
			"************************************************");
		Item iList[] = getValidationItems();
		for (int j = 0; j < iList.length; j++) {
			if (iList[j] != null) {
				SchoolLogger.logger.log(
					Level.INFO,
					iList[j].getFieldName() + ": " + iList[j].toString());
			}
		}
	}
}
